/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.actions.modelo;

import com.mapping.Modelo;
import com.opensymphony.xwork2.ActionSupport;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author PARDmx
 */
@Namespace(value = "/")
@Action(value = "eliminarModeloP", results = {
    @Result(name = "success", location = "/GestionModelos/resultadoEliminarModelo.jsp")})
public class EliminarModeloAction extends ActionSupport{
    private int idModelo;
    private Modelo modelo;
    private String mensaje = "El Modelo se ha eliminado satisfactoriamente :";    

    @Override
    public String execute() throws Exception {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("inventarios");
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();
        tx.begin();                     
        modelo = em.getReference(Modelo.class,idModelo);       
        em.remove(modelo);
        em.flush();
        tx.commit();
        em.close();         
        return SUCCESS;        
    }

    public void setIdModelo(int idModelo) {
        this.idModelo = idModelo;
    }

    public Modelo getModelo() {
        return modelo;
    }

    public String getMensaje() {
        return mensaje;
    }
    
    
}
